package com.los;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @program: java8
 * @description: stream特性之map
 * @author: Yujuan
 * @create: 2018-06-14 10:14
 **/
public class StreamMap {

    public static void main(String[] args) {
        List<Integer> integers= Arrays.asList(1,2,3,5,6,7,8,7,6,9,1,2);
        List<Integer> result=integers.stream().map(integer -> integer*2).collect(Collectors.toList());
        System.out.println(result);

        listDish().stream().map(dish -> dish.getName()).forEach(System.out::println);

        //flatmap flat 扁平化
        String[] words={"hello","world"};

        Stream<String[]>  stream= Arrays.stream(words).map(w-> w.split(""));
//        stream.forEach(System.out::println);
        System.out.println(stream);

        Stream<String> stringStream=stream.flatMap(Arrays::stream);
        stringStream.distinct().forEach(System.out::println);


    }

    private static List<Dish> listDish(){
        return  Arrays.asList(
                new Dish("pork", false, 800, Dish.Type.MEAT),
                new Dish("beef", false, 700, Dish.Type.MEAT),
                new Dish("chicken", false, 400, Dish.Type.MEAT),
                new Dish("french fries", true, 530, Dish.Type.OTHER),
                new Dish("rice", true, 350, Dish.Type.OTHER),
                new Dish("season fruit", true, 120, Dish.Type.OTHER),
                new Dish("pizza", true, 550, Dish.Type.OTHER),
                new Dish("prawns", false, 300, Dish.Type.FISH),
                new Dish("salmon", false, 450, Dish.Type.FISH));
    }
}
